package com.ruoyi.web.controller.persona;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GeneralBase;
import com.ruoyi.system.service.IGeneralBaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通用知识库Controller
 *
 * @author ruoyi
 * @date 2025-03-13
 */
@RestController
@RequestMapping("/general/general")
public class GeneralBaseController extends BaseController {
    @Autowired
    private IGeneralBaseService generalBaseService;

    /**
     * 查询通用知识库列表
     */
    @PreAuthorize("@ss.hasPermi('general:general:list')")
    @GetMapping("/list")
    public TableDataInfo list(GeneralBase generalBase) {
        startPage();
        List<GeneralBase> list = generalBaseService.selectGeneralBaseList(generalBase);
        return getDataTable(list);
    }

    /**
     * 导出通用知识库列表
     */
    @PreAuthorize("@ss.hasPermi('general:general:export')")
    @Log(title = "通用知识库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GeneralBase generalBase) {
        List<GeneralBase> list = generalBaseService.selectGeneralBaseList(generalBase);
        ExcelUtil<GeneralBase> util = new ExcelUtil<GeneralBase>(GeneralBase.class);
        util.exportExcel(response, list, "通用知识库数据");
    }

    /**
     * 获取通用知识库详细信息
     */
    @PreAuthorize("@ss.hasPermi('general:general:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(generalBaseService.selectGeneralBaseById(id));
    }

    /**
     * 新增通用知识库
     */
    @PreAuthorize("@ss.hasPermi('general:general:add')")
    @Log(title = "通用知识库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GeneralBase generalBase) {
        return toAjax(generalBaseService.insertGeneralBase(generalBase));
    }

    /**
     * 修改通用知识库
     */
    @PreAuthorize("@ss.hasPermi('general:general:edit')")
    @Log(title = "通用知识库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GeneralBase generalBase) {
        return toAjax(generalBaseService.updateGeneralBase(generalBase));
    }

    /**
     * 删除通用知识库
     */
    @PreAuthorize("@ss.hasPermi('general:general:remove')")
    @Log(title = "通用知识库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(generalBaseService.deleteGeneralBaseByIds(ids));
    }
}
